<template>
	<view class="box" :style="{ overflow: showWant? 'hidden' : 'auto' }">
		<uNavbar :title="titles" :bgColor="backgroundColor"></uNavbar>
		<!-- 商品 -->
		<view class="commodity flex_Z">
			<view class="commodity_top">
				<image class="tupians" :src="threeMoxing" mode="aspectFit"></image>
			</view>
			<view class="commodity_btm flex_ZC">
				<view class="commodity_btm_box">
					<view class="commodity_name flex_c">
						<text :class="checkLength(this.productName)>8 ? 'namess':'names'">{{this.productName}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 发行方 -->
		<view class="issuer flex_Z">
			<view class="issuer_box flex_dq">
				<image :src="shopBrand.logo" mode="aspectFill"></image>
				<view class="issuer_btm flex_Z">
					<text class="f28">发行方</text>
					<text class="f24 c9">{{shopBrand.name}}</text>
				</view>
			</view>
			<view class="issuer_box mart30 flex_dq" @click="goTrend">
				<image class="qushi" src="../../static/image/i_trend.png" mode=""></image>
				<view class="issuer_btm flex_Z">
					<text class="f28">成交趋势</text>
				</view>
			</view>
		</view>
		<view class="notice_box flex_ZC">
			<view class="notice flex_c">
				<text class="tiao"></text>
				<text>购买需知</text>
				<text class="tiao"></text>
			</view>
			<view class="xuzhi">
				<rich-text class="f24 colors" :nodes="nodeCentent4"></rich-text>
			</view>
		</view>
		<view class="technology flex_c">
			<image src="../../static/image/thl.png" mode=""></image>
		</view>
		<view class="buy_btn flex_ld_a">
			<text :class="hold?'caise':'ssss'" @click="submitPay">立即购买</text>
		</view>
		<view class="empty3"></view>

		<!-- 立即购买弹窗 -->
		<u-overlay :show="showWant" zIndex="999" @click="showWant = false">
			<view class="want_box flex_Z" @tap.stop>
				<view class="want ">
					<view class="want_tit flex_dq">
						<text class="f36">今日销售</text>
						<text class="f36">（{{realTimeSales}}份）</text>
					</view>
				</view>
				<view class="choice flex_ld">
					<view class="choice_l flex_c" @click="isChange">
						<text class="f28">价格</text>
						<view class="choice_r flex_Z">
							<u-icon name="arrow-up" :color="taggle == 1? '#d67d04':'#333333'" size="10"></u-icon>
							<u-icon name="arrow-down" :color="taggle == 1? '#333333':'#d67d04'" size="10"></u-icon>
						</view>
					</view>
					<text class="f28" v-if="duoxuan" @click="multipleChoice">切换</text>
					<text class="f28" v-else @click="multipleChoice">多选</text>
				</view>
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltolower="isScrolltolower">

					<view class="list_s flex_Z " v-for="(item,index) in marketAllList" :key="index">
						<view class="csqx" :class="item.is_member?'me_daoj':''">
							<view class="list_s_box flex_ld">
								<text class="f32"
									style="font-size: 26rpx;">{{item.prop_name}}X{{item.ful_number}}</text>
								<view class=" flex_dq" v-show="!duoxuan">
									<text v-show="item.is_member" class="f28 c2 mys">我的</text>
									<text v-show="!item.is_member" class="f28 c5" @click="goBuy(item)">去购买</text>
									<u-icon v-show="!item.is_member" name="arrow-right" color="#A68A64"
										size="16"></u-icon>
								</view>
								<view class="selects" v-show="duoxuan">
									<image src="../../static/icon/i_checkbox.png" mode="aspectFill"
										v-if="item.selected " @click="isClickDuo(item,index)"></image>
									<image src="../../static/icon/i_checkbox1.png" mode=""
										v-if="!item.selected &&  !item.is_member" @click="isClickDuo(item,index)">
									</image>
								</view>
							</view>
							<view class="list_s_box flex_ld">
								<!-- <text class="f28 colora">{{item.goods_number}}/{{item.circulation}}</text> -->
								<view class=" flex_dq">
									<image class="fhtb" src="../../static/icon/fhtb.png" mode=""></image>
									<text class="f32">单价:{{item.ful_rent_proportion}}</text>
								</view>
								<view class=" flex_dq">
									<image class="fhtb" src="../../static/icon/fhtb.png" mode=""></image>
									<text class="f32">总价:{{item.price}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="empty3"></view>
					<view class="empty2"></view>
				</scroll-view>
				<view class="batch flex_dq" v-if="duoxuan">
					<view class="batch_l flex_Z">
						<view class="batch_l_t flex_dq">
							<text class="f24">当前余额：{{balance}}</text>
							<text class="f24">已选：{{selectId.length}}</text>
						</view>
						<text class="f32">共计：{{returnFloat(allMoney)}}</text>
					</view>
					<view class="batch_r flex_c" @click="bulkPurchase">
						<text>批量购买</text>
					</view>
				</view>
			</view>



		</u-overlay>

		<!-- 支付弹窗 -->
		<u-popup :show="showPay" @close="showPay = false" closeable bgColor="transparent">
			<view class="pay flex_ZC">
				<text>购买信息</text>
				<view class="pay_box flex_Z">
					<view class="pay_box_c flex_ld">
						<text>藏品名称</text>
						<text class="c3">{{temporary.prop_name}}</text>
					</view>
					<view class="pay_box_c flex_ld">
						<text>购买数量</text>
						<text class="c3">x {{selectId.length}}</text>
					</view>

					<view class="pay_money  flex_ld">
						<text>应支付金额</text>
						<view class=" flex_dq">
							<image class="pay_img" src="../../static/icon/i_money.png" mode=""></image>
							<text class="c3 go_pay">{{returnFloat(allMoney)}}</text>
						</view>
					</view>
				</view>
				<view class="buyNow flex_c" @click="goPay">
					<text>立即支付</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getuserinfo
	} from "../../api/index.js";
	import {
		marketList,
		propInfo,
		propmarketList,
	} from "../../api/store.js";
	export default {
		data() {
			return {
				page: 1,
				size: 10,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				inx: 0,
				allMoney: 0, //多选的总价
				numbers: 1, //数量
				pinpaiId: '', //品牌id
				threeMoxing: '', //3D模型
				ids: '', //藏品id
				balance: '', //余额
				spaceId: '', //出售藏品id
				hold: 0, //自己是否有出售商品
				goodsId: '', //商品id
				Keys: '', //秘钥id
				isPay: '', //是否设置交易密码
				realName: '', //是否实名认证
				parityBit: '', //状态
				contents: '', //提示语
				remind: '', //是否允许购买提示词
				productName: '', //商品名称
				remind: '', //是否允许购买提示词
				tipShow: false, //提示弹窗
				allowPay: false, //是否允许购买
				showWant: false, //弹窗
				showPay: false, //支付弹窗
				duoxuan: false, //切换多选
				taggle: true, // 价格升降
				akkkk: false,
				allowPurchases: false, //是否允许购买拦截
				selectId: [], // 多选的id
				infoDetail: {}, //商品信息
				goodsSeries: {}, //系列
				shopBrand: {}, //品牌信息
				marketAllList: [], //正在出售的商品
				realTimeSales: '', //实时销售
				temporary: {}, //暂存购买的商品信息
				nodeCentent: '', //富文本
				nodeCentent2: '', //富文本
				nodeCentent4: '', //富文本
				titles: '', //标题
				backgroundColor: "transparent", //标题背景颜色
				list1: ['藏品描述', '权益介绍'],
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				overflow: "hidden",
				propnum: 1,
			}
		},
		onLoad(e) {
			console.log(e);
			this.ids = e.id
			this.goodsId = e.goodsId
		},
		onShow(e) {
			// 每次到详情关闭所有弹窗
			this.tipShow = false
			this.allowPay = false
			this.showPay = false
			this.selectId = []
			this.allMoney = 0
			this.getuser()
			this.isMarketList()
			this.isGoodsInfo()
		},
		methods: {
			isScrolltolower(e) {
				console.log(e);
				if (!this.akkkk) {
					this.page += 1
					this.isMarketList()
				}
			},
			// 检验是图片还是模型
			checkMediaType(url) {
				// console.log(url);
				// 获取文件扩展名
				var index = url.lastIndexOf(".");
				var ext = url.substr(index + 1);
				console.log(ext);
				var imageExtensions = ['glb', 'gltf', ];
				// 判断模型
				if (imageExtensions.includes(ext)) {
					return '3dmx';
				}
			},
			// 动态计算字体大小
			checkLength(v) {
				const realLength = v.length;
				return realLength;
			},
			// 用户信息
			getuser() {
				getuserinfo().then(res => {
					console.log(res)
					this.isPay = res.data.is_pay
					this.realName = res.data.is_real
					this.balance = res.data.balance
				})
			},
			// 计算价格
			returnFloat(value) {
				var value = Math.round(parseFloat(value) * 100) / 100;
				var xsd = value.toString().split(".");
				if (xsd.length == 1) {
					value = value.toString() + ".00";
					return value;
				}
				if (xsd.length > 1) {
					if (xsd[1].length < 2) {
						value = value.toString() + "0";
					}
					return value;
				}
			},
			// 产品详情中当前产品所有的列表
			isMarketList() {
				let data = {
					prop_id: this.goodsId,
					order_by: this.taggle ? 'price asc' : 'price desc',
					page: this.page,
				}
				propmarketList(data).then(res => {
					console.log(res)
					this.realTimeSales = res.data.rent_pay_number
					let list = res.data.prop_list.data;
					this.marketAllList = this.page == 1 ? list : this.marketAllList.concat(list);
					console.log(this.marketAllList);
					if (list.length < this.size) {
						console.log(1111);
						this.akkkk = true
						this.status = 'nomore';
					} else {
						console.log(23222);
						this.akkkk = false
						this.status = 'loading';
					}
				})
			},
			// 初始化详情
			isGoodsInfo() {
				let data = {
					id: this.ids,
				};
				propInfo(data).then(res => {
					console.log(res);
					this.infoDetail = res.data.prop
					this.productName = res.data.prop.prop_name

					if (res.data.prop.purchase_info) {
						var htmlContent4 = res.data.prop.purchase_info
						htmlContent4 = htmlContent4.replace(/\r\n/g, "<p/>");
						this.nodeCentent4 = htmlContent4;
					}
					this.threeMoxing = res.data.prop.three_d
					this.shopBrand = res.data.prop.shop_brand
					
				})
			},

			isChange() {
				this.taggle = !this.taggle
				this.selectId = []
				this.allMoney = 0
				this.page = 1
				this.isMarketList()
			},
			// 多选
			multipleChoice() {
				this.duoxuan = !this.duoxuan
				this.selectId = []
				this.allMoney = 0
				this.marketAllList.forEach((item, index) => {
					item.selected = false
				})
			},
			// 去购买
			goBuy(item) {
				if (item.is_member) {
					uni.$u.toast('不能购买自己出售的商品');
				} else {
					this.selectId = []
					this.showPay = true,
						this.showWant = false
					this.temporary = item
					this.selectId.push(item.id);
					this.allMoney = item.price
				}
			},
			// 批量购买
			bulkPurchase() {
				// 没有实名认证
				// if (!this.realName) {
				// 	this.tipShow = true
				// 	this.parityBit = 'smrz'
				// 	return;
				// }
				// // 没有设置交易密码
				// if (!this.isPay) {
				// 	this.tipShow = true
				// 	this.parityBit = 'jymm'
				// 	return;
				// }
				// // 限购上限
				// if (this.infoDetail.limit) {
				// 	uni.$u.toast('超过当前产品限购数量');
				// 	return
				// }
				// 判断用户时候可以购买
				// if (this.allowPay) {
				if (this.selectId.length == 0) {
					uni.$u.toast('请选择商品');
					return;
				} else {
					this.showPay = true,
						this.showWant = false
				}
			},

			isClickDuo(item, index) {
				this.temporary = item
				// console.log(item);
				// console.log(index);
				let idIndex = this.selectId.indexOf(item.id);
				this.marketAllList[index].selected = !this.marketAllList[index].selected;
				// 如果点击得已经被勾选
				if (idIndex != -1) {
					//这个返回的是被删除的内容
					this.selectId.splice(idIndex, 1);
					this.allMoney -= Number(item.price)
				} else {
					this.selectId.push(item.id);
					this.allMoney += Number(item.price)
				}
				console.log(this.selectId);
				console.log(this.allMoney);
			},
			// 立即支付
			submitPay() {
				this.showWant = true
			},
			// 拦截校验
			goNixtPage() {
				console.log(this.parityBit);
				if (this.parityBit == 'jymm') {
					uni.navigateTo({
						url: '/pagesMy/setting/amendsafepassword?first=' + 'first'
					})
				} else if (this.parityBit == 'smrz') {
					uni.navigateTo({
						url: '/pagesMy/setting/realNameAuthentication'
					})
				} else if (this.parityBit == 'gmmy') {
					// 购买秘钥
					uni.navigateTo({
						url: '/pagesMy/brandCenter/numbercard?id=' + this.pinpaiId
					})
				}
			},
			// 立即购买
			goPay() {
				let data = {
					id: this.selectId.join(',')
				}
				let productCacheInfo = {
					productType: 3,
					selectId: this.selectId.join(','),
					goodsId: this.goodsId,
					allMoney: this.returnFloat(this.allMoney),
					notice: this.infoDetail.purchase_info,
				}
				uni.setStorageSync("productCacheInfo", productCacheInfo)
				uni.navigateTo({
					url: '/pagesMy/brandCenter/paymentCenter'
				})
			},
			isSell() {
				uni.navigateTo({
					url: '/pagesMy/mycollection/collectionlist?id=' + this.spaceId
				})
			},
			goTrend() {
				uni.navigateTo({
					url: `/pagesMy/proporder/proptrend?id=${this.goodsId}`
				})
			},
		},

		//触底加载
		onReachBottom() {
			console.log('触底加载');
			if (this.status != 'nomore') {
				this.page = this.page + 1
				this.isMarketList()
			}
		},

	}
</script>

<style scoped>
	.box {
		position: relative;
		z-index: 99;
		width: 750rpx;
		height: 100vh;

	}

	@font-face {
		font-family: 'iconfont2';
		src: url("~@/iconfont/YouSheBiaoTiHei.ttf");
	}

	.commodity {
		width: 560rpx;
		margin: 0 auto;
		margin-top: -90rpx;
	}

	.commodity_top {
		position: relative;
		width: 92%;
		height: 580rpx;
		margin: 0 auto;
		z-index: 7;
	}

	.tupians {
		position: absolute;
		top: 20rpx;
		left: 50%;
		width: 100%;
		height: 560rpx;
		transform: translateX(-50%);
		z-index: 5;
	}

	.commodity_btm {
		position: relative;
		width: 532rpx;
		height: 282rpx;
		background: url(../../static/image/bg12.png);
		background-size: 100% 100%;
		margin: 0 auto;
		z-index: 6;
	}

	.commodity_btm_box {
		width: 58%;
		margin-top: 120rpx;
	}

	.commodity_name {
		font-size: 36rpx;
		margin-bottom: 30rpx;
		text-align: center;
	}

	.names {
		font-size: 36rpx;
		color: #9E845F;
	}

	.namess {
		font-size: 30rpx;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		color: #9E845F;
	}


	.issuer {
		width: 690rpx;
		margin: 0 auto;

	}

	.issuer_box {
		width: 100%;
		height: 116rpx;
		border-radius: 20rpx;
		background: #F2F2F2;
	}

	.issuer_box>image {
		width: 76rpx;
		height: 76rpx;
		border-radius: 50%;
		margin: 0 26rpx;
	}

	.mart30{
		margin-top: 30rpx;
	}

	.issuer_btm {
		width: 78%;
	}

	.issuer_btm>text:nth-child(2) {
		/* background: pink; */
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}


	.equity {
		width: 100%;
		font-size: 32rpx;
	}

	.equity_top {
		width: 100%;
		height: 86rpx;
		line-height: 86rpx;
		padding-left: 24rpx;
	}

	.notice_box {
		width: 690rpx;
		background: #F2F2F2;
		border-radius: 20rpx;
		margin: 24rpx auto;
		padding-bottom: 20rpx;
	}

	.notice {
		width: 100%;
		padding: 20rpx 0;
	}

	.notice>text:nth-child(2) {
		font-size: 36rpx;
		color: #A68A64;
		font-family: 'iconfont2';
		margin: 0 24rpx;
	}

	.tiao {
		width: 154rpx;
		height: 6rpx;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
		border-radius: 4rpx;
	}

	.xuzhi {
		width: 660rpx;
		margin: 0 auto;
		padding: 0 50rpx;
		overflow: auto;
	}

	.colors {
		color: #666666;
		line-height: 1.6;
	}

	.technology {
		width: 100%;
		/* background: pink; */
	}

	.technology>image {
		width: 70%;
		height: 60rpx;
	}

	.buy_btn {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 152rpx;
		background: #ffffff;
	}


	.caise {
		width: 224rpx;
		height: 76rpx;
		line-height: 76rpx;
		border-radius: 36rpx;
		border: 1rpx solid #FFFFFF;
		font-size: 32rpx;
		text-align: center;
		color: #ffffff;
		border: none !important;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
	}

	.ssss {
		width: 690rpx;
		height: 76rpx;
		line-height: 76rpx;
		border-radius: 36rpx;
		border: 1rpx solid #FFFFFF;
		font-size: 32rpx;
		text-align: center;
		color: #ffffff;
		border: none !important;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
	}


	.scroll-Y {
		min-height: 400rpx;
		max-height: 1300rpx;
	}

	.want_box {
		position: fixed;
		z-index: 500;
		bottom: 0;
		width: 100%;
		min-height: 400rpx;
		max-height: 1300rpx;
		background: #E0DDDA;
		border-radius: 20rpx 20rpx 0 0;
		color: #333333;
	}

	.want {
		display: flex;
		flex-direction: column;
		justify-content: center;
		width: 100%;
		padding: 40rpx 0 40rpx 40rpx;
		border-bottom: 1rpx solid #ffffff10;
	}


	.choice {
		width: 100%;
		padding: 0 40rpx;
		margin: 30rpx 0;
	}

	.choice>text {
		width: 132rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		border-radius: 40rpx;
		border: 2rpx solid #A68A64;
		color: #A68A64;
	}

	.choice_l {
		width: 132rpx;
		height: 46rpx;
		line-height: 46rpx;
		text-align: center;
		background: #F2F2F2;
		border-radius: 40rpx;
	}

	.choice_r {
		margin-left: 10rpx;
	}


	.csqx {
		position: relative;
		width: 670rpx;
		height: 184rpx;
		border-radius: 22rpx;
		margin: 20rpx auto;
		background: #F2F2F2;
	}

	.me_daoj {
		opacity: 0.5 !important;
	}

	.mys {
		padding: 0rpx 14rpx;
		border-radius: 10rpx;
		color: #ffffff !important;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
	}

	.list_s_box {
		width: 100%;
		padding: 10rpx 32rpx;
		margin-top: 20rpx;
	}

	.list_s_box>text:nth-child(1) {
		width: 75%;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}

	.selects {
		width: 10%;
	}

	.selects>image {
		width: 36rpx;
		height: 36rpx;
	}

	.fhtb {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}

	.batch {
		position: absolute;
		bottom: 0;
		width: 100%;
		height: 150rpx;
		background: #FFFFFF;
	}

	.batch_l {
		width: 60%;
		padding-left: 40rpx;
	}

	.batch_l_t {
		color: #333333;
		margin-bottom: 20rpx;
	}

	.batch_l_t>text {
		margin-right: 30rpx;
	}

	.batch_r {
		width: 40%;
	}


	.batch_r>text {
		width: 224rpx;
		height: 76rpx;
		line-height: 76rpx;
		text-align: center;
		font-size: 32rpx;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
		border-radius: 40rpx;
		color: #ffffff;
	}

	.pay {
		width: 100%;
		background: #E0DDDA;
		border-radius: 20rpx 20rpx 0 0;
		color: #333333;
		overflow: auto;
	}


	.pay>text {
		font-size: 36rpx;
		margin: 60rpx 0;
	}

	.pay_box {
		width: 694rpx;
		background: #F2F2F2;
		border-radius: 18rpx;
	}

	.pay_box_c {
		font-size: 24rpx;
		padding: 28rpx 28rpx 0;
	}

	.pay_box_c>text:nth-child(1) {
		color: #666666;
	}

	.pay_box_c>text:nth-child(2) {
		width: 70%;
		text-align: right;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}


	.pay_money {
		width: 92%;
		padding: 30rpx 0;
		margin: 30rpx auto 0;
		font-size: 24rpx;
		border-top: 1rpx solid #ffffff20;
	}

	.pay_img {
		width: 32rpx;
		height: 32rpx;
	}

	.go_pay {
		font-size: 36rpx;
		font-family: 'iconfont2';
		margin-left: 10rpx;
	}

	.buyNow {
		width: 690rpx;
		height: 88rpx;
		background: linear-gradient(274deg, #AB8E68, #D7BA93);
		border-radius: 40rpx;
		margin: 46rpx 0;
		color: #ffffff;
	}

</style>